<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary
    x:Class="OpenLS.Spreadsheet.UI.FormattingRulePropertiesResources"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ss="clr-namespace:OpenLS.Spreadsheet;assembly=OpenLS.Spreadsheet"
    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals"
    xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    xmlns:Resources="clr-namespace:OpenLS.Spreadsheet.UI.Internals.Resources">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ssui:EnumResources/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
    <DataTemplate DataType="{x:Type Internals:NamedDifferentialStyleRecord}">
        <TextBlock Text="{Binding Path=Name}"></TextBlock>
    </DataTemplate>
    <DataTemplate DataType="{x:Type ssui:ConditionalFormattingRuleViewModel}" x:Key="styleRecordSelector">
        <ComboBox ItemsSource="{Binding Items}" 
                  SelectedItem="{Binding SelectedItem}">
            <ComboBox.Resources>
                <DataTemplate DataType="{x:Type ssui:Message}">
                    <Button Content="{Binding Text}" Command="{Binding Command}" CommandParameter="{Binding RelativeSource={RelativeSource Self}}"/>
                </DataTemplate>
            </ComboBox.Resources>
        </ComboBox>
    </DataTemplate>
    <DataTemplate DataType="{x:Type ss:CellIsFormattingRule}">
        <Grid MinWidth="300">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <StackPanel Grid.ColumnSpan="2" Orientation="Horizontal">
                <TextBlock Text="{x:Static Resources:UIStringTable.FormatCellsThatAre}" />
                <TextBlock Text=" " />
                <TextBlock Text="{Binding Operator, Converter={x:Static Internals:SpreadsheetConverters.EnumToNameConverter}}" Typography.Capitals="Titling" />
                <TextBlock Text=":"/>
            </StackPanel>
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBox Text="{Binding Formula1}" Grid.Row="1" ssui:ControlHelper.AutoSelect ="True" />
                <TextBlock Text="{x:Static Resources:UIStringTable.And}" Name="between1" Grid.Column="1" Visibility="Collapsed" ></TextBlock>
                <TextBox Text="{Binding Formula2}" Grid.Column="2" Name="between2" Visibility="Collapsed" />
            </Grid>
            <ContentPresenter Grid.Column="1" Grid.Row="1" Content="{Binding Converter={x:Static Internals:SpreadsheetConverters.ViewModelFactory}}" ContentTemplate="{StaticResource styleRecordSelector}"></ContentPresenter>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Operator}" Value="Between">
                <Setter TargetName="between1" Property="Visibility" Value="Visible" />
                <Setter TargetName="between2" Property="Visibility" Value="Visible" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <DataTemplate DataType="{x:Type ss:ContainsTextFormattingRule}">
        <Grid MinWidth="300">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label Content="{x:Static Resources:UIStringTable.FormatCellsThatContainsTheText}" Grid.ColumnSpan="2"/>
            <TextBox Text="{Binding Text}" Grid.Row="1" ssui:ControlHelper.AutoSelect ="True"/>
            <ContentPresenter Grid.Column="1" Grid.Row="1" Content="{Binding Converter={x:Static Internals:SpreadsheetConverters.ViewModelFactory}}" ContentTemplate="{StaticResource styleRecordSelector}"></ContentPresenter>
        </Grid>
    </DataTemplate>
    <DataTemplate DataType="{x:Type ss:Top10FormattingRule}">
        <Grid MinWidth="300">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label Name="label" Content="{x:Static Resources:UIStringTable.FormatCellsThatRankInTheTop}" Grid.ColumnSpan="2"/>
            <TextBox Text="{Binding Rank}" ssui:ControlHelper.AutoSelect ="True" Grid.Row="1" />
            <TextBlock Name="percent" Text="%" Grid.Row="1" Grid.Column="1"/>
            <ContentPresenter Grid.Row="1" Grid.Column="2" Content="{Binding  Converter={x:Static Internals:SpreadsheetConverters.ViewModelFactory}}" ContentTemplate="{StaticResource styleRecordSelector}"></ContentPresenter>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Bottom}" Value="True">
                <Setter TargetName="label" Property="Content" Value="{x:Static Resources:UIStringTable.FormatCellsThatRankInTheBottom}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding Percent}" Value="False">
                <Setter TargetName="percent" Property="Visibility" Value="Hidden"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    <DataTemplate DataType="{x:Type ss:AboveAverageFormattingRule}">
        <Grid MinWidth="300">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label Name="label" Content="{x:Static Resources:UIStringTable.FormatCellsThatAreAboveAverage}" Grid.ColumnSpan="2"/>
            <TextBox Text="{Binding Formula1}" ssui:ControlHelper.AutoSelect ="True" />
            <ContentPresenter Grid.Column="1" Content="{Binding Converter={x:Static Internals:SpreadsheetConverters.ViewModelFactory}}" ContentTemplate="{StaticResource styleRecordSelector}"></ContentPresenter>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding AboveAverage}" Value="False">
                <Setter TargetName="label" Property="Content" Value="{x:Static Resources:UIStringTable.FormatCellsThatAreBelowAverage}"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    <DataTemplate DataType="{x:Type ss:UniqueValuesFormattingRule}">
        <Grid MinWidth="300">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label Content="{x:Static Resources:UIStringTable.FormatUniqueCells}" />

            <ContentPresenter Grid.Column="1" Content="{Binding Converter={x:Static Internals:SpreadsheetConverters.ViewModelFactory}}" ContentTemplate="{StaticResource styleRecordSelector}"></ContentPresenter>
        </Grid>
    </DataTemplate>
    <DataTemplate DataType="{x:Type ss:DuplicateValuesFormattingRule}">
        <Grid MinWidth="300">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label Content="{x:Static Resources:UIStringTable.FormatDuplicateCells}" />
            <ContentPresenter Grid.Column="1" Content="{Binding Converter={x:Static Internals:SpreadsheetConverters.ViewModelFactory}}" ContentTemplate="{StaticResource styleRecordSelector}"></ContentPresenter>
        </Grid>
    </DataTemplate>
    
    <DataTemplate DataType="{x:Type ss:TimePeriodFormattingRule}">
        <Grid MinWidth="300">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label Content="{x:Static Resources:UIStringTable.FormatCellsThatContainADateOccuring}" Grid.ColumnSpan="2"></Label>
            
            <ComboBox Grid.Row="1" SelectedItem="{Binding TimePeriod}">
                <ComboBox.ItemsSource>
                    <Binding Source="{x:Type ss:TimePeriod}">
                        <Binding.Converter>
                            <ssui:EnumValueEnumerator />
                        </Binding.Converter>
                    </Binding>
                </ComboBox.ItemsSource>
            </ComboBox>
            <TextBlock Text="{x:Static Resources:UIStringTable.With}" Grid.Column="1" Grid.Row="1"/>
            <ContentPresenter Grid.Row="1" Grid.Column="2" Content="{Binding Converter={x:Static Internals:SpreadsheetConverters.ViewModelFactory}}" ContentTemplate="{StaticResource styleRecordSelector}"></ContentPresenter>
        </Grid>
    </DataTemplate>
</ResourceDictionary>